package hr.ctg.component.tag;

import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.webapp.UIComponentELTag;

public class HtmlObjektRatingTag12 extends UIComponentELTag {
	String rating;
	String votes;
	String najvisaOcjena;
	String targetedIdObjekta;
	private MethodExpression actionListener = null;
	private MethodExpression action = null;
	private String immediate = null;

	@Override
	public String getComponentType() {
		return "HtmlObjektRating12";
	}

	@Override
	public String getRendererType() {
		return null;
	}

	@Override
	protected void setProperties(final UIComponent component) {
		super.setProperties(component);
		System.out.println("Obrada parametara prosljedjenih komponenti...");
		final ExpressionFactory ef = FacesContext.getCurrentInstance()
				.getApplication().getExpressionFactory();
		if (rating != null) {
			System.out.println("rating nije null...");
			final ValueExpression ve = ef.createValueExpression(rating,
					String.class);
			component.setValueExpression("rating", ve);
		}
		if (votes != null) {
			System.out.println("votes nije null...");
			final ValueExpression ve = ef.createValueExpression(votes,
					String.class);
			component.setValueExpression("votes", ve);
		}
		System.out.println("Najvisa ocjena: " + najvisaOcjena);
		if (najvisaOcjena != null) {
			System.out.println("najvisa ocjena nije null...");
			final ValueExpression ve = ef.createValueExpression(najvisaOcjena,
					String.class);
			component.setValueExpression("najvisaocjena", ve);
		}
		if (targetedIdObjekta != null) {
			System.out.println("idObjekta nije null...");
			final ValueExpression ve = ef.createValueExpression(
					targetedIdObjekta, String.class);
			component.setValueExpression("targetedidobjekta", ve);
		}
		if (actionListener != null) {
			System.out.println("actionListener nije null...");
			// ((HtmlObjektRating12)component).setListener(actionListener);
		}
		if (action != null) {
			System.out.println("action nije null...");
			// ((HtmlObjektRating12)component).setListener(action);
		}
		if (immediate != null) {
			System.out.println("immediate nije null...");
			final ValueExpression ve = ef.createValueExpression(immediate,
					String.class);
			component.setValueExpression("immediate", ve);
		}

	}

	@Override
	public void release() {
		super.release();
		votes = null;
		rating = null;
		targetedIdObjekta = null;
		najvisaOcjena = null;
	}

	public void setAction(final MethodExpression action) {
		this.action = action;
	}

	public void setActionListener(final MethodExpression actionListener) {
		this.actionListener = actionListener;
	}

	public void setImmediate(final String immediate) {
		this.immediate = immediate;
	}

	public void setRating(final String rating) {
		this.rating = rating;
	}

	public void setVotes(final String votes) {
		this.votes = votes;
	}

	public void setNajvisaOcjena(final String najvisaOcjena) {
		this.najvisaOcjena = najvisaOcjena;
	}

	public void setTargetedIdObjekta(final String targetedIdObjekta) {
		this.targetedIdObjekta = targetedIdObjekta;
	}

}
